﻿using FictionsDownload.DAL;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace FictionsDownload.Model
{
    [Table("Folder")]
    public class FolderModel:BaseModel
    {
        /// <summary>
        /// 最外层的唯一文件夹节点
        /// </summary>
        public const string BaseNode = "BASE_NODE";
        public FolderModel():base()
        {
            FolderId = BaseNode;
        }
        public string Name { get; set; }
        public string Remarks { get; set; }
        public string FolderId { get; set; }
        public virtual List<BookModel> Books { get; set; }
        public void Delete(IDAL db)
        {
            //查找Folder中所有的Folder并且删除
            db.All<FolderModel>().Where(f => f.FolderId == Id).ToList().ForEach(f => f.Delete(db));
            //查找Folder中所有的Book并且删除
            db.All<BookModel>().Where(d => d.FolderId == Id).ToList().ForEach(b => b.Delete(db));
            db.Delete(this);
        }
    }
}
